#include "StdAfx.h"
#include "Test_bcl_pair.h"
 
CPPUNIT_TEST_SUITE_REGISTRATION(CTest_bcl_pair);

CTest_bcl_pair::CTest_bcl_pair(void)
{
}

CTest_bcl_pair::~CTest_bcl_pair(void)
{
}

void CTest_bcl_pair::AssertIntConstructor()
{
	int nFirst = 0;
	int nSecond = 1;
	CPPUNIT_ASSERT(IntConstructor(nFirst,nSecond).first == nFirst && IntConstructor(nFirst,nSecond).second == nSecond);
}

void CTest_bcl_pair::AssertFloatConstructor()
{
	float fFirst = 0.5;
	float fSecond = 1.5;
	CPPUNIT_ASSERT(fabs(FloatConstructor(fFirst,fSecond).first - fFirst) < FLT_EPSILON && 
				   fabs(FloatConstructor(fFirst,fSecond).second - fSecond) < FLT_EPSILON);
}

void CTest_bcl_pair::AssertTcharConstructor()
{
	TCHAR szFirst = 'a';
	TCHAR szSecond = 'b';
	CPPUNIT_ASSERT(TcharConstructor(szFirst,szSecond).first == szFirst && 
		           TcharConstructor(szFirst,szSecond).second == szSecond);
}

void CTest_bcl_pair::AssertTStringConstructor()
{
	TCHAR* pszFirst = L"Hello";
	TCHAR* pszSecond = L"World";
	CPPUNIT_ASSERT(StrCmpI(TStringConstructor(pszFirst,pszSecond).first,pszFirst) == 0 &&
		           StrCmpI(TStringConstructor(pszFirst,pszSecond).first,pszSecond) != 0);
}

void CTest_bcl_pair::AssertCompare1()
{
	int nFirst = 0;
	int nSecond = 1;
	bcl::pair<int,int> _p1 = bcl::make_pair(nFirst,nSecond);
	bcl::pair<int,int> _p2 = bcl::make_pair(nFirst,nSecond);
	bcl::pair<int,int> _p3 = bcl::make_pair(nSecond,nFirst);
	CPPUNIT_ASSERT(_p1 == _p2);
	CPPUNIT_ASSERT(_p1 != _p3);

}

void CTest_bcl_pair::AssertCompare2()
{
	TCHAR* pszFirst = L"Hello";
	TCHAR* pszSecond = L"World";
	bcl::pair<TCHAR*,TCHAR*> _p1(pszFirst,pszSecond);
	bcl::pair<TCHAR*,TCHAR*> _p2(pszSecond,pszFirst);
	//compare the address
	CPPUNIT_ASSERT(_p1 != _p2);
}

void CTest_bcl_pair::AssertCompare3()
{
	int nFirst = 0;
	int nSecond = 1;
	float fFirst = 0.5;
	float fSecond = 1.5;
	bcl::pair<float,float> _p1(nFirst,nSecond);
	bcl::pair<float,float> _p2(fFirst,fSecond);
	CPPUNIT_ASSERT(_p2 > _p1);

}

void CTest_bcl_pair::AssertCompare4()
{
	TCHAR szFirst = 'a';
	TCHAR szSecond = 'b';
	int nFirst = 0;
	int nSecond = 1;
	bcl::pair<TCHAR,TCHAR> _p1(szFirst,szSecond);
	bcl::pair<TCHAR,TCHAR> _p2(nFirst,nSecond);
	CPPUNIT_ASSERT(_p1 >= _p2);
}

void CTest_bcl_pair::AssertCompare5()
{
	std::string strFirst = "Hello";
	std::string strSecond = "World";
	CPPUNIT_ASSERT(bcl::make_pair(strFirst,strSecond) != bcl::make_pair(strSecond,strFirst));
	CPPUNIT_ASSERT(bcl::make_pair(strFirst,strSecond) == bcl::make_pair(strFirst,strSecond));
}

void CTest_bcl_pair::AssertCompare6()
{
	std::string strFirst = "Hello";
	std::string strSecond = "World";
	bcl::pair<std::string,std::string> _p1(strFirst,strSecond);
	bcl::pair<std::string,std::string> _p2(strSecond,strFirst);
	CPPUNIT_ASSERT(_p1 <= _p2);
	CPPUNIT_ASSERT(!(_p1 >= _p2));
}

bcl::pair<int,int> CTest_bcl_pair::IntConstructor(int _a,int _b)
{
	return bcl::make_pair(_a,_b);
}

bcl::pair<float,float> CTest_bcl_pair::FloatConstructor(float _a,float _b)
{
	return bcl::make_pair(_a,_b);
}

bcl::pair<TCHAR,TCHAR> CTest_bcl_pair::TcharConstructor(TCHAR _a,TCHAR _b)
{
	return bcl::make_pair(_a,_b);
}

bcl::pair<TCHAR*,TCHAR*> CTest_bcl_pair::TStringConstructor(TCHAR* _pA,TCHAR* _pB)
{
	return bcl::make_pair(_pA,_pB);
}
